gsk: Add a way to reset profiler counters
authorMatthias Clasen <mclasen@redhat.com>
Tue, 26 Sep 2017 00:58:10 +0000 (20:58 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 26 Sep 2017 00:58:10 +0000 (20:58 -0400)
It is often useful to count things per-frame, and reset
the counter afterwards.

gsk/gskprofiler.c
gsk/gskprofilerprivate.h

index bc7301046b353139dbdbaae00a3d1af5b6723bfd..be83d66a5607496c71fddc06990cdda611bec9cb 100644 (file)
@@ -206,6 +206,26 @@ gsk_profiler_counter_inc (GskProfiler *profiler,
   gsk_profiler_counter_add (profiler, counter_id, 1);
 }
 
+void
+gsk_profiler_counter_set (GskProfiler *profiler,
+                          GQuark       counter_id,
+                          gint64       value)
+{
+  NamedCounter *counter;
+
+  g_return_if_fail (GSK_IS_PROFILER (profiler));
+
+  counter = gsk_profiler_get_counter (profiler, counter_id);
+  if (counter == NULL)
+    {
+      g_critical ("No counter '%s' (id:%d) found; did you forget to call gsk_profiler_add_counter()?",
+                  g_quark_to_string (counter_id), counter_id);
+      return;
+    }
+
+  counter->value = value;
+}
+
 void
 gsk_profiler_counter_add (GskProfiler *profiler,
                           GQuark       counter_id,
@@ -217,7 +237,11 @@ gsk_profiler_counter_add (GskProfiler *profiler,
 
   counter = gsk_profiler_get_counter (profiler, counter_id);
   if (counter == NULL)
-    return;
+    {
+      g_critical ("No counter '%s' (id:%d) found; did you forget to call gsk_profiler_add_counter()?",
+                  g_quark_to_string (counter_id), counter_id);
+      return;
+    }
 
   counter->value += increment;
 }
index e30a810432d9d3d6b7cafbf71313d6339bebae7d..ca0f44518b3f2193a6c21e1755b369e8ade7bb84 100644 (file)
@@ -25,6 +25,9 @@ void            gsk_profiler_counter_inc        (GskProfiler *profiler,
 void            gsk_profiler_counter_add        (GskProfiler *profiler,
                                                  GQuark       counter_id,
                                                  gint64       increment);
+void            gsk_profiler_counter_set        (GskProfiler *profiler,
+                                                 GQuark       counter_id,
+                                                 gint64       value);
 void            gsk_profiler_timer_begin        (GskProfiler *profiler,
                                                  GQuark       timer_id);
 gint64          gsk_profiler_timer_end          (GskProfiler *profiler,